/* 
 * Copyright 2014 ShangDao.Ltd  All rights reserved.
 * SiChuan ShangDao.Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * @HomeListAdapter.java  2014-9-9 下午4:11:26 - Carson
 * @author Guzhu
 * @email:muyi126@163.com
 * @version 1.0
 */

package com.android.tiango.baba.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.image.ImageLoader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.scsd.tiango.R;
import com.android.tiango.baba.entity.ImageBean;
import com.android.tiango.baba.entity.IndexHotProductTopicsBean;
import com.android.tiango.baba.entity.SimpleProductBean;
import com.android.tiango.baba.view.RoundImageView;

public class HomeListAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<IndexHotProductTopicsBean> list;
	private ImageLoader mLoader;

	public HomeListAdapter(Context context, ArrayList<IndexHotProductTopicsBean> list) {
		this.context = context;
		this.list = list;
		mLoader=new ImageLoader(context, R.drawable.ic_default);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (null == convertView) {
			convertView = LayoutInflater.from(context).inflate(R.layout.item_topicpost, null);
			holder = new ViewHolder();
			holder.ly_bghead = (LinearLayout) convertView.findViewById(R.id.ly_bghead);
			holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.tv_date = (TextView) convertView.findViewById(R.id.tv_date);
			holder.tv_actcomments = (TextView) convertView.findViewById(R.id.tv_actcomments);
			holder.tv_acttoview = (TextView) convertView.findViewById(R.id.tv_acttoview);
			holder.iv_brandimg = (RoundImageView) convertView.findViewById(R.id.iv_brandimg);
			holder.tv_brand = (TextView) convertView.findViewById(R.id.tv_brand);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}
        IndexHotProductTopicsBean bean = list.get(position);
        if (null!=bean) {
            SimpleProductBean product = bean.getSimpleProduct();
            holder.tv_date.setText(bean.getStartTime());
            holder.tv_actcomments.setText(bean.getReplyNumber());
            holder.tv_acttoview.setText(bean.getReadNumber());
            if (null!=product) {
            	holder.tv_title.setText(product.getProductName());
            	holder.tv_brand.setText(product.getMerchant());
            	ArrayList<ImageBean> imgs = product.getProductImage();
            	if (null!=imgs&&imgs.size()>0) {
            		mLoader.loadImage(imgs.get(0).getImageUrl(),holder.iv_brandimg);
				}
            	
			}else{
				holder.tv_title.setText("");
            	holder.tv_brand.setText("");
            	mLoader.loadImage("",holder.iv_brandimg);
			}
            
			
		}
		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				

			}
		});
		return convertView;
	}

	class ViewHolder {
		private LinearLayout ly_bghead;
		private TextView tv_title;
		private TextView tv_date;
		private TextView tv_actcomments;
		private TextView tv_acttoview;
		private RoundImageView iv_brandimg;
		private TextView tv_brand;

	}
}
